﻿@using Abp.Collections.Extensions
@using MyCompanyName.AbpZeroTemplate.Web.Areas.AppAreaName.Views.Shared.Components.AppAreaNameMenu
@model UserMenuItemViewModel
@{
    Layout = null;
    var theme = await GetTheme();
}

@if (Model.MenuItem.Items.IsNullOrEmpty())
{
    <li class="kt-menu__item @GetActiveLinkClass(Model)" aria-haspopup="true">
        <a href="@Model.MenuItem.CalculateUrl(ApplicationPath)" class="kt-menu__link ">
            @if (!Model.RootLevel)
                {
            <i class="kt-menu__link-bullet kt-menu__link-bullet--dot">
                <span></span>
            </i>
                }
            <span class="kt-menu__link-text">@Model.MenuItem.DisplayName</span>
        </a>
    </li>
}
else
{
    <li class="kt-menu__item kt-menu__item--submenu @GetMenuItemClass(Model) @GetActiveMenuClass(Model)" data-ktmenu-submenu-toggle="click" aria-haspopup="true">
        <a href="javascript:;" class="kt-menu__link kt-menu__toggle">
            <span class="kt-menu__link-text">@Model.MenuItem.DisplayName</span>
            @if (theme.BaseSettings.Header.HeaderMenuArrows)
            {
                <i class="kt-menu__hor-arrow la la-angle-down"></i>
            }
        </a>
        <div class="kt-menu__submenu kt-menu__submenu--classic @GetSubMenuClass(Model)">
            <ul class="kt-menu__subnav">
                @for (var i = 0; i < Model.MenuItem.Items.Count; i++)
                    {
                        var childMenuItem = Model.MenuItem.Items[i];
                        if (!childMenuItem.IsVisible)
                        {
                            continue;
                        }

                @await Html.PartialAsync("Components/AppAreaNameMenu/_TopUserMenuItem", new UserMenuItemViewModel
                {
                    MenuItem = childMenuItem,
                    MenuItemIndex = i,
                    CurrentPageName = Model.CurrentPageName,
                    RootLevel = false
                })
                    }
            </ul>
        </div>
    </li>
}

@functions
{
    public static string GetActiveLinkClass(UserMenuItemViewModel model)
    {
        var activeClass = " ";
        if (!model.MenuItem.IsMenuActive(model.CurrentPageName))
        {
            return activeClass;
        }

        activeClass += "kt-menu__item--active ";

        return activeClass;
    }

    public static string GetActiveMenuClass(UserMenuItemViewModel model)
    {
        var activeClass = " ";
        if (!model.MenuItem.IsMenuActive(model.CurrentPageName))
        {
            return activeClass;
        }

        activeClass += "kt-menu__item--here ";

        return activeClass;
    }

    public static string GetMenuItemClass(UserMenuItemViewModel model)
    {
        var menuItemClass = " ";
        if (model.RootLevel)
        {
            menuItemClass += "kt-menu__item--rel ";
        }

        return menuItemClass;
    }

    public static string GetSubMenuClass(UserMenuItemViewModel model)
    {
        var menuItemClass = " ";
        if (model.RootLevel)
        {
            menuItemClass += "kt-menu__submenu--left ";
        }
        else
        {
            menuItemClass += "kt-menu__submenu--right ";
        }

        return menuItemClass;
    }
}